package crack.four_point_test;

import math2.MathUtilities;
import crack.AbstractFourPointTestUsingSDAElementDemo;
import fem2.AbstractStructuralCrackDemo;
import fem2.Element;
import fem2.MaterialModel;
import fem2.MeshPart;
import fem2.MeshUtilities;
import fem2.Model;
import fem2.Node;
import fem2.element.crack_sda.SKONConstantJumpCSTElement;
import fem2.material.cohesive_law.CohesiveLaw;
import fem2.material.cohesive_law.Mode1SanchoExponentialCohesiveLaw;
import fem2.strategies.ArcLengthSolutionStrategyWithDistanceConstraint;
import fem2.strategies.Strategy;

public class FourPointTestAbaqusMesh2SKONConstantJumpCSTElementAndSanchoExponentialCohesiveLaw
		extends AbstractFourPointTestUsingSDAElementDemo {

	public FourPointTestAbaqusMesh2SKONConstantJumpCSTElementAndSanchoExponentialCohesiveLaw() {
		meshFileName = "abaqus-mesh2-skon-sancho.msh";
	}

	@Override
	public CohesiveLaw createCohesiveLaw(Model m) {
		double ft = 2.8;
		double Gf = 0.1;
		return new Mode1SanchoExponentialCohesiveLaw(Gf, ft);
	}

	@Override
	public Element createElement(MeshPart mp, MaterialModel mm, CohesiveLaw cl) {
		// Element e = new StructuralElement(mp, mm);
		Element e = new SKONConstantJumpCSTElement(mp, mm, cl);
		return e;
	}

	public Strategy createStrategy(Model m) {
		Node n1 = MeshUtilities.seekNodeNearest(m.getMesh(), 654.0, 0);
		Node n2 = MeshUtilities.seekNodeNearest(m.getMesh(), 668.0, 0);

		// double[] dArray = LinAlgUtilities.createLambdaArray(new double[] {
		// 0.0131, 0.0001 },
		// new int[] { 1, 20 });
		// double[] dArray = LinAlgUtilities.createLambdaArray(new double[] {
		// 0.0131, 0.0001 },
		// new int[] { 1, 600 });

		// double[] dArray = LinAlgUtilities.createLambdaArray(new double[] {
		// 0.0131, 0.001 },
		// new int[] { 1, 20});
		// double[] dArray = LinAlgUtilities.createLambdaArray(new double[] {
		// 0.0131, 0.001 },
		// new int[] { 1, 40});
		double[] dArray = MathUtilities.createLambdaArray(new double[] { 0.0131, 0.001 },
				new int[] { 1, 60 }); // does not converge at step 43

		Strategy st = new ArcLengthSolutionStrategyWithDistanceConstraint(m, dArray, n1, n2);

		return st;
	}

	public static void main(String[] args) {
		AbstractStructuralCrackDemo demo = new FourPointTestAbaqusMesh2SKONConstantJumpCSTElementAndSanchoExponentialCohesiveLaw();

		demo.run();
	}
}
